package com.aaa.service.impl;

import com.aaa.commen.domain.RentReceive;
import com.aaa.commen.domain.UserLogin;
import com.aaa.commen.entity.Result;
import com.aaa.commen.query.RentReceiveQuery;
import com.aaa.mapper.OperateLogMapper;
import com.aaa.mapper.RentReceiveMapper;
import com.aaa.mapper.UserDeptMapper;
import com.aaa.service.IRentReceiveService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.data.redis.serializer.JdkSerializationRedisSerializer;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 * @PackageName: com.aaa.service.impl
 * @ClassName: RentReceiveServiceImpl
 * @Description:
 * @author: 王嘉威
 * @Date: 2021/1/19 17:18
 */
@Service
public class RentReceiveServiceImpl extends ServiceImpl<RentReceiveMapper, RentReceive> implements IRentReceiveService {

    @Autowired
    private RentReceiveMapper rentReceiveMapper;

    /**
     * 查询所有租金已收取信息
     */
    @Override
    public Result queryRentReceiveInfo(RentReceiveQuery rentReceiveQuery) {
        IPage<RentReceive> rentReceiveIPage = rentReceiveMapper.queryRentReceiveInfo(new Page<RentReceive>(rentReceiveQuery.getCurrPage(), rentReceiveQuery.getCount()), rentReceiveQuery);
        return Result.success(rentReceiveIPage);
    }

    /**
     * 收取即将到期的租金，并将相关信息添加到租金收取信息表
     */
    @Override
    @Transactional
    public Result insertRentReceive(Map<String, String> map) {
        // 获取支付方式，并放入map中
        String payMethod = rentReceiveMapper.queryPayMethod(map.get("payMethod"));
        map.put("payMethod", payMethod);
        // 根据合同号查询房产号,年租金并放入map中
        Map<String, String> map1 = rentReceiveMapper.queryContractInfo(map.get("contractId"));
        map.putAll(map1);
        map.put("id",null);
        // 将map作为参数往数据表中添加信息
        int i = rentReceiveMapper.insertRentReceive(map);
        if (i > 0) {
            return Result.success("已收取");
        }
        return Result.error("收取失败");
    }
}
